/**
 * 递增顺序搜索树，中序遍历
 */
class Solution {
    private static TreeNode head = null;
    private static TreeNode cur = null;
    public TreeNode increasingBST(TreeNode root) {
        if(root == null) {
            return null;
        }
        head = new TreeNode(-1);
        cur = head;
        indexOrder(root);
        return head.right;
    }

    private void indexOrder(TreeNode root) {
        if(root == null) {
            return;
        }
        indexOrder(root.left);
        root.left = null;
        cur.right = root;
        cur = cur.right;
        indexOrder(root.right);
    }
}